<%@ Page Title="" Language="C#" MasterPageFile="~/Views/Shared/User.Master" Inherits="System.Web.Mvc.ViewPage" %>

<%@ Register assembly="AjaxControlToolkit" namespace="AjaxControlToolkit" tagprefix="cc1" %>

<script runat="server">



    protected void LinkButton3_Click(object sender, EventArgs e)
    {
        KnowlegdeBlock.InsertParameters[0].DefaultValue = (GridView1.FooterRow.FindControl("DropDownList2") as DropDownList).Text;
        KnowlegdeBlock.InsertParameters[1].DefaultValue = (GridView1.FooterRow.FindControl("TextBox1") as TextBox).Text;
        KnowlegdeBlock.InsertParameters[2].DefaultValue = (GridView1.FooterRow.FindControl("TextBox2") as TextBox).Text;
        KnowlegdeBlock.InsertParameters[3].DefaultValue = "1";

        KnowlegdeBlock.Insert();
    }



    protected void GridView1_RowCommand(object sender, GridViewCommandEventArgs e)
    {
        if (e.CommandName == "Detail")
        {
            string id = (GridView1.Rows[Convert.ToInt32(e.CommandArgument)].FindControl("Label4") as Label).Text;
            Response.Redirect("/Home/CourseOfMajor/?id=" + id);
        }
    }
</script>

<asp:Content ID="Content1" ContentPlaceHolderID="TitleContent" runat="server">
	ManageMajor
</asp:Content>

<asp:Content ID="Content2" ContentPlaceHolderID="MainContent" runat="server">

    <h2>ManageMajor</h2>
    <cc1:TabContainer ID="TabContainer1" runat="server" ActiveTabIndex="0" 
        Width="952px">
        <cc1:TabPanel ID="TabPanel3" runat="server" HeaderText="Block Knowledge">
        <ContentTemplate>
            <asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="False" 
                CellPadding="4" DataKeyNames="ID" DataSourceID="KnowlegdeBlock" 
                ForeColor="#333333" GridLines="None" ShowFooter="True" 
                onrowcommand="GridView1_RowCommand" Width="556px">
                <RowStyle BackColor="#F7F6F3" ForeColor="#333333" />
                <AlternatingRowStyle BackColor="White" ForeColor="#284775" />
                <Columns>
                    <asp:TemplateField HeaderText="ID" InsertVisible="False" SortExpression="ID">
                        <ItemTemplate>
                            <asp:Label ID="Label4" runat="server" Text='<%# Bind("ID") %>'></asp:Label>
                        </ItemTemplate>
                    </asp:TemplateField>
                    <asp:BoundField DataField="MajorID" HeaderText="MajorID" 
                        SortExpression="MajorID" Visible="False" />
                    <asp:TemplateField HeaderText="MajorName" SortExpression="MajorName">
                        <EditItemTemplate>
                            <asp:DropDownList ID="DropDownList1" runat="server" 
                                DataSourceID="SqlDataSource1" DataTextField="Name" DataValueField="ID" 
                                SelectedValue='<%# Bind("MajorID") %>'>
                            </asp:DropDownList>
                            <asp:SqlDataSource ID="SqlDataSource1" runat="server" 
                                ConnectionString="<%$ ConnectionStrings:CDIO1ConnectionString1 %>" 
                                SelectCommand="SELECT [Name], [ID] FROM [Major]"></asp:SqlDataSource>
                        </EditItemTemplate>
                        <ItemTemplate>
                            <asp:Label ID="Label3" runat="server" Text='<%# Bind("MajorName") %>'></asp:Label>
                        </ItemTemplate>
                    </asp:TemplateField>
                    <asp:TemplateField HeaderText="Name" SortExpression="Name">
                        <EditItemTemplate>
                            <asp:TextBox ID="TextBox1" runat="server" Text='<%# Bind("Name") %>'></asp:TextBox>
                        </EditItemTemplate>
                        <ItemTemplate>
                            <asp:Label ID="Label1" runat="server" Text='<%# Bind("Name") %>'></asp:Label>
                        </ItemTemplate>
                    </asp:TemplateField>
                    <asp:TemplateField HeaderText="Credit" SortExpression="Credit">
                        <EditItemTemplate>
                            <asp:TextBox ID="TextBox2" runat="server" Text='<%# Bind("Credit") %>'></asp:TextBox>
                        </EditItemTemplate>
                        <ItemTemplate>
                            <asp:Label ID="Label2" runat="server" Text='<%# Bind("Credit") %>'></asp:Label>
                        </ItemTemplate>
                    </asp:TemplateField>
                    <asp:BoundField DataField="Status" HeaderText="Status" SortExpression="Status" 
                        Visible="False" />
                    <asp:ButtonField CommandName="Detail" Text="Detail" />
                </Columns>
                <EditRowStyle BackColor="#999999" />
                <FooterStyle BackColor="#5D7B9D" Font-Bold="True" ForeColor="White" />
                <HeaderStyle BackColor="#5D7B9D" Font-Bold="True" ForeColor="White" />
                <PagerStyle BackColor="#284775" ForeColor="White" HorizontalAlign="Center" />
                <SelectedRowStyle BackColor="#E2DED6" Font-Bold="True" ForeColor="#333333" />
            </asp:GridView>
            <asp:SqlDataSource ID="KnowlegdeBlock" runat="server" 
                ConnectionString="<%$ ConnectionStrings:CDIO1ConnectionString1 %>" 
                DeleteCommand="UPDATE [KnowledgeBlock] SET  [Status] = 0 WHERE [ID] = @ID" 
                InsertCommand="INSERT INTO [KnowledgeBlock] ([MajorID], [Name], [Credit], [Status]) VALUES (@MajorID, @Name, @Credit, @Status)" 
                SelectCommand="SELECT KnowledgeBlock.ID, KnowledgeBlock.MajorID, KnowledgeBlock.Name, KnowledgeBlock.Credit, KnowledgeBlock.Status, Major.Name AS MajorName FROM KnowledgeBlock INNER JOIN Major ON KnowledgeBlock.MajorID = Major.ID WHERE (KnowledgeBlock.Status = @Status) AND (KnowledgeBlock.MajorID = @MajorID)" 
                UpdateCommand="UPDATE [KnowledgeBlock] SET [MajorID] = @MajorID, [Name] = @Name, [Credit] = @Credit WHERE [ID] = @ID">
                <SelectParameters>
                    <asp:Parameter DefaultValue="1" Name="Status" Type="Int32" />
                    <asp:QueryStringParameter Name="MajorID" QueryStringField="id" Type="Int32" />
                </SelectParameters>
                <DeleteParameters>
                    <asp:Parameter Name="ID" Type="Int32" />
                </DeleteParameters>
                <UpdateParameters>
                    <asp:Parameter Name="MajorID" Type="Int32" />
                    <asp:Parameter Name="Name" Type="String" />
                    <asp:Parameter Name="Credit" Type="Int32" />
                    <asp:Parameter Name="ID" Type="Int32" />
                </UpdateParameters>
                <InsertParameters>
                    <asp:Parameter Name="MajorID" Type="Int32" />
                    <asp:Parameter Name="Name" Type="String" />
                    <asp:Parameter Name="Credit" Type="Int32" />
                    <asp:Parameter Name="Status" Type="Int32" />
                </InsertParameters>
            </asp:SqlDataSource>
        </ContentTemplate>
        </cc1:TabPanel>
    </cc1:TabContainer>
    <p>
    </p>
 

</asp:Content>
